﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultipleGridAction.aspx.cs" Inherits="icrmGridActions.MultipleGridAction" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>Getting CRM grid info</title>
  <script type="text/jscript">
    function window.onload()
    {
      var message = document.getElementById("message");   
          
      var sSelectedRows = window.dialogArguments;
      // If sSelectedRows is empty, do not execute the update.
      if (sSelectedRows == null)
        sSelectedRows = "";
      if (sSelectedRows == "" || sSelectedRows.length == 0)
      {
        message.innerHTML = "You must select at least one record in order to use this feature.";
        alert("You must select a record in order to use this feature.");
        window.close();
      }
      else 
      {
        // Wait 100 milliseconds and then execute the UpdateAccounts
        // method.
        message.innerHTML = "Getting selected info ...";   
        window.setTimeout(UpdateAccounts, 100);
      }
    }
    
    function UpdateAccounts()
    {
      var url = location.href;
      //alert(url);
      if (url.lastIndexOf("?") > -1)
        url = url + "&sState=Update";
      else
        url = url + "?sState=Update";
      // Create an XML string of entity-instance IDs bounded by <record> tags.
      sSelectedRecords = "<records>" + window.dialogArguments.toString() +
                         "</records>";

      // Do an Http POST to invoke the ASP.NET Web page. The sState argument
      // is set to 'Update'.
      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      xmlhttp.open("POST",url, false);
      // Send the string of entity-instance IDs.
      xmlhttp.send(sSelectedRecords);

      // Create an XML document in which the response message will be
      // loaded.
      var oResultXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      oResultXmlDoc.async = false;

      // Extract any XML message returned in the Http response and load
      // it into the XML document. An <eom /> tag is used to indicated
      // the end of the response message from the code-behind page.
      var eom = xmlhttp.responseText.indexOf("<eom />");
      var xmlMessage = xmlhttp.responseText.substring(0,eom);
      oResultXmlDoc.loadXML(xmlMessage);
      // If errors were returned in the Http response, display them.
      var oNodeError = oResultXmlDoc.selectSingleNode("error");
      if(oNodeError != null)
      {
          alert(oNodeError.text);
      } 
      window.close();   
    }
  </script>

</head>
<body>
  <form id="form1" runat="server">
  <div id="message" style="vertical-align: middle; text-align: center;">
  </div>
  <div id="Div1" style="vertical-align: middle; text-align: center;">
    <img src="_imgs/btn_lookup_resolving.gif" />
  </div>
  </form>
</body>
</html>
